<script lang="ts" setup>
import AuditForm from "@/components/audit/AuditForm.vue";
import { applyInfoEntityApi } from "@/api/activity";
import { emit } from "process";
const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  modelValue: {
    type: Object,
    required: true,
  },
  title: {
    type: String,
  },
});

const emits = defineEmits(["update:show", "update:modelValue", "confirm"]);

const submitLoading = ref(false),
  auditForm = ref({});

const auditFormRef = ref();

// 提交审核
const submitAuditForm = () => {
  auditFormRef.value.validate(async (valid: any) => {
    if (valid) {
      submitLoading.value = true;
      let rs = await applyInfoEntityApi(props.modelValue);
      if (rs.code == 200) {
        ElMessage.success(`已提交审核`);
        emits("update:show", false);
        emits("confirm");
      }
      submitLoading.value = false;
    }
  });
};

const onClose = () => {
  emits("update:show", false);
};

const update = (val) => {
  emits("update:modelValue", val);
};
</script>
<template>
  <Dialog
    :model-value="show"
    :title="title"
    :loading="submitLoading"
    :width="700"
    @confirm="submitAuditForm"
    @close="onClose"
  >
    <AuditForm
      v-if="show"
      ref="auditFormRef"
      :model-value="modelValue"
      @change="update"
    />
  </Dialog>
</template>
